﻿Imports Microsoft.VisualBasic
Imports System.Data.Objects
Imports System.Data


Public Class CamarasRepositorio

    'Public Function GuardarTransaccionActividad(ByVal folio As Folios, ByVal actividad As Actividades, _
    '                                            ByVal listaActividadIntegrantes As List(Of Actividad_Integrantes)) As Boolean
    '    Dim repository As New GeneralRepositorio
    '    Dim success As Boolean = False
    '    Try
    '        Using transaction As New TransactionScope()
    '            Try
    '                repository.EntityObjectContext.CreateObjectSet(Of Folios)().AddObject(folio)
    '                If repository.EntityObjectContext.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave) > 0 Then
    '                    Dim idFolioInsertado As Integer = folio.Id_Folio
    '                    actividad.Folios.Id_Folio = idFolioInsertado
    '                    repository.EntityObjectContext.CreateObjectSet(Of Actividades)().AddObject(actividad)
    '                    If repository.EntityObjectContext.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave) > 0 Then
    '                        Dim idActividadInsertada As Integer = actividad.Id_Actividad
    '                        For Each actividadIntegrante As Actividad_Integrantes In listaActividadIntegrantes
    '                            actividadIntegrante.Actividades.Id_Actividad = idActividadInsertada
    '                            repository.EntityObjectContext.CreateObjectSet(Of Actividad_Integrantes)().AddObject(actividadIntegrante)
    '                        Next
    '                        If repository.EntityObjectContext.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave) > 0 Then
    '                            success = True
    '                            transaction.Complete()
    '                        End If

    '                    End If
    '                End If

    '            Catch ex As Exception

    '            End Try

    '        End Using

    '        If success = True Then
    '            repository.EntityObjectContext.AcceptAllChanges()
    '        End If

    '    Finally
    '        repository.EntityObjectContext.Dispose()
    '    End Try
    '    Return success
    'End Function
    'Public Function BuscarActividadPorFolio(ByVal strFolio As String) As Actividades
    '    Dim act As Actividades = Nothing
    '    Dim repositoryBase As EntityRepositorioBase(Of Actividades) = New EntityRepositorioBase(Of Actividades)()

    '    Try
    '        repositoryBase.EntityObjectContext.ContextOptions.LazyLoadingEnabled = True
    '        act = repositoryBase.BuscarUnico(Function(x) x.Folios.Folio_Act = strFolio)

    '    Catch ex As Exception
    '        'repository.Dispose()
    '    End Try

    '    Return act
    'End Function

    'Public Function BuscarActividadesModalPopUpActivas() As List(Of Object)
    '    Dim listaIntegrantes As New List(Of Object)
    '    Dim genRep As New EntityRepositorioBase(Of Actividades)()
    '    Dim query As IEnumerable(Of Object) = From i In genRep.EntityObjectContext.Actividades
    '                                          Where i.Estatus = True
    '                                           Select New With {.Desc_Corta = i.Desc_Corta,
    '                                                            .Id_Actividad = i.Id_Actividad,
    '                                                            .Fecha_Inicio = i.Fecha_Inicio,
    '                                                            .Fecha_Termino = i.Fecha_Termino,
    '                                                            .Folio = i.Folios.Folio_Act
    '                                                             }




    '    Return Query.ToList()

    'End Function

    'Public Function GuardarActividad(ByVal actividad As Actividades) As Boolean
    '    Dim success As Boolean = False
    '    Dim repository As EntityRepositorioBase(Of Camaras) = New EntityRepositorioBase(Of Camaras)()
    '    Try

    '        repository.Agregar(actividad)
    '        For Each fila As Actividad_Integrantes In actividad.Actividad_Integrantes
    '            repository.EntityObjectContext.ObjectStateManager.ChangeObjectState(fila.Integrantes, EntityState.Unchanged)
    '        Next
    '        If repository.GuardarCambios() > 0 Then
    '            success = True
    '        End If

    '    Finally
    '        repository.Dispose()
    '    End Try
    '    Return success
    'End Function

    Function BuscarCamarasPorRegionZonaPob(ByVal region As Integer, ByVal zona As Integer, ByVal pob As Integer) As List(Of Camaras)
        Dim listaCamaras As New List(Of Camaras)
        Dim genRep As New EntityRepositorioBase(Of Camaras)()
        Dim query As IEnumerable(Of Camaras) = Nothing
        query = From i In genRep.EntityObjectContext.Camaras
                    Where i.id_Region = region And i.id_Zona = zona And i.id_Poblacion = pob
        listaCamaras = query.ToList()

        Return listaCamaras
    End Function

End Class
